<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="socket.io.min.js"></script>
</head>
<body>
    <div id="msgDiv"></div>
    <input type="text" id="text">
    <input type="button" value="发送" onclick="send()">

    <script>
       var socket = io.connect("http://127.0.0.1:3000");
       socket.on("pushMsg",(data) =>{
           var divObj = document.getElementById("msgDiv");
           divObj.innerHTML += `<div>${data}</div>`;
       });

       function send(){
            var msg = document.getElementById("text").value;
            socket.emit("sendMsg",msg);
       }
    </script>
</body>
</html>